package com.jiaanpei.frameproject.widget;

import android.app.Dialog;
import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.jiaanpei.frameproject.R;
import com.wang.avi.AVLoadingIndicatorView;

import java.util.Random;

import butterknife.BindView;

public class MyProgressDialog extends Dialog {
    public static final String TAG = "MyProgressDialog";
    private static MyProgressDialog customProgressDialog = null;
    @BindView(R.id.avi)
    AVLoadingIndicatorView avi;

    public MyProgressDialog(Context context) {
        super(context);
    }

    public MyProgressDialog(Context context, int theme) {
        super(context, theme);
    }


    /**
     * 产生随机数随机样式
     */
    private static final String[] INDICATORS=new String[]{
            "BallPulseIndicator",
            "BallGridPulseIndicator",
            "BallClipRotateIndicator",
            "BallClipRotatePulseIndicator",
            "SquareSpinIndicator",
            "BallClipRotateMultipleIndicator",
            "BallPulseRiseIndicator",
            "BallRotateIndicator",
            "CubeTransitionIndicator",
            "BallZigZagIndicator",
            "BallZigZagDeflectIndicator",
            "BallTrianglePathIndicator",
            "BallScaleIndicator",
            "LineScaleIndicator",
            "LineScalePartyIndicator",
            "BallScaleMultipleIndicator",
            "BallPulseSyncIndicator",
            "BallBeatIndicator",
            "LineScalePulseOutIndicator",
            "LineScalePulseOutRapidIndicator",
            "BallScaleRippleIndicator",
            "BallScaleRippleMultipleIndicator",
            "BallSpinFadeLoaderIndicator",
            "LineSpinFadeLoaderIndicator",
            "TriangleSkewSpinIndicator",
            "PacmanIndicator",
            "PacmanIndicator",
            "PacmanIndicator",
            "BallGridBeatIndicator",
            "SemiCircleSpinIndicator",
            "com.wang.avi.sample.MyCustomIndicator"
    };

    /**
     *
     * @param context
     * @param content   提示内容
     * @return
     */
    public static MyProgressDialog createDialog(Context context,String content) {
        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(R.layout.ac_loading_dialog, null);// 得到加载view
        customProgressDialog = new MyProgressDialog(context, R.style.MyProgressDialog);
        customProgressDialog.setContentView(view);
        customProgressDialog.getWindow().getAttributes().gravity = Gravity.CENTER;

        TextView tvTips = (TextView)view.findViewById(R.id.tv_title);
        if(TextUtils.isEmpty(content)) {
            tvTips.setText("");
        }else {
            tvTips.setText(content);
        }
        AVLoadingIndicatorView avi = (AVLoadingIndicatorView)view.findViewById(R.id.avi);
//        avi.setIndicator("PacmanIndicator");//设置动画的样式

//        int i = new Random().nextInt(30) + 1;
//        Log.e(TAG,""+i);

        avi.setIndicator(INDICATORS[2]);//设置动画的样式0 2-5  17 22
        avi.show();
        customProgressDialog.setCancelable(false); //// 不可以用“返回键”取消



        return customProgressDialog;
    }
}
